package com.alibaba.base.common;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.base.util.JsonUtil;

@Component
public class ExceptionHandle implements HandlerExceptionResolver{

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		PrintWriter writer=null;
			try {
				//获取输出流
				 writer = response.getWriter();
				 writer.println(JsonUtil.error("服务端异常"));
			} catch (IOException e) {
				
			}finally {
				if(writer!=null) {
					writer.close();
				}
			}
			
		return null;
	}

}
